cmake_minimum_required(VERSION 2.6)
project(CodeBase)

if("${CMAKE_SYSTEM_NAME}" STREQUAL "Darwin")
    message(STATUS "Platform: Darwin")
    add_definitions(-DAPPLE)
elseif("${CMAKE_SYSTEM_NAME}" STREQUAL "Windows")
    message(STATUS "Platform: Win32")
    add_definitions(-DWIN32)
else()
    message(STATUS "Platform: Unix")
    add_definitions(-DUNIX -D_FILE_OFFSET_BITS=64 -D_LFS_LARGEFILE=1)

    # Switch off -fstrict-aliasing.
    add_definitions(-fno-strict-aliasing)

    if (C4_MINIMIZE_SIZE)
        # To remove unused code while linking (--gc-sections linker option)
        add_definitions(-ffunction-sections -fdata-sections)
    endif()
endif()

if(CMAKE_SIZEOF_VOID_P EQUAL 4)
    add_definitions(-D__32BIT__)
elseif(CMAKE_SIZEOF_VOID_P EQUAL 8)
    add_definitions(-D__64BIT__)
endif()

# set global define of endianness
include(TestBigEndian)
TEST_BIG_ENDIAN(bigendian)
if(bigendian)
    add_definitions(-DS4BYTEORDER_3210 -DS4BYTE_SWAP)
endif()

set(c4_SOURCES
    b4block.c
    b4node.c
    c4.c
    c4baspas.c
    # c4buffer.c
    c4code.c
    c4com.c
    # c4com2.c
    # c4conect.c
    # c4conlow.c
    c4const.c
    #c4hook.c
    #c4send.c
    c4set.c
    # c4thread.c
    c4trans.c
    # c4util.c
    d4append.c
    d4bottom.c
    d4close.c
    d4create.c
    d4data.c
    d4date.c
    d4extra.c
    d4field.c
    d4file.c
    d4flush.c
    d4fresh.c
    d4go.c
    d4index.c
    # d4info.c
    # d4inline.c
    d4lock.c
    d4modify.c
    d4open.c
    d4opt.c
    d4pack.c
    d4positi.c
    d4remove.c
    d4seek.c
    d4skip.c
    d4tag.c
    d4top.c
    d4unlock.c
    d4write.c
    d4zap.c
    df4lock.c
    df4unlok.c
    e4calc.c
    e4calc_2.c
    e4error.c
    # e4event.c
    e4expr.c
    e4functi.c
    e4not_s.c
    e4parse.c
    e4string.c
    f4ass_f.c
    f4char.c
    f4close.c
    f4create.c
    # f4cur.c
    f4double.c
    # f4dttime.c
    f4field.c
    f4file.c
    f4filese.c
    f4flag.c
    f4flush.c
    f4info.c
    f4int.c
    f4lock.c
    f4long.c
    f4memo.c
    # f4null.c
    f4open.c
    f4opt.c
    f4ptr.c
    f4str.c
    f4temp.c
    f4true.c
    f4write.c
    f4wstr.c
    i4add.c
    i4addtag.c
    i4check.c
    i4conv.c
    i4create.c
    # i4dump.c
    i4index.c
    i4info.c
    i4init.c
    i4key.c
    i4lock.c
    i4ntag.c
    i4positi.c
    i4remove.c
    i4tag.c
    # i4thread.c
    l4link.c
    # l4lock_c.c
    # l4mutex.c
    # m4check.c
    m4create.c
    m4file.c
    m4map.c
    m4memo.c
    m4memory.c
    o4opt.c
    # r4area.c
    # r4bit.c
    # r4drive2.c
    # r4driver.c
    # r4group.c
    r4log.c
    # r4obj.c
    # r4regs.c
    r4reinde.c
    r4reindx.c
    r4relate.c
    # r4report.c
    # r4save.c
    # r4save_2.c
    # r4style.c
    # r4total.c
    s4init.c
    s4initfr.c
    s4next.c
    s4quick.c
    # s4signal.c
    s4sort.c
    # sema4.c
    u4name.c
    u4util.c
)

set(c4class_SOURCES
    d4data_p.cpp
    f4info_p.cpp
    f4seq.cpp
    s4str.cpp
    s4string.cpp
    t4info.cpp
)

include_directories(${CodeBase_SOURCE_DIR})

add_library(c4 STATIC ${c4_SOURCES})
add_library(c4class STATIC ${c4class_SOURCES})

if(WIN32)
    # compile C code as C++ code
    set(MORE_C_FLAGS "/TP")
else()

if (C4_MINIMIZE_SIZE)
    # enable GNU extensions to C99
    set(MORE_C_FLAGS "-std=gnu99")
else()
    # compile C code as C++ code
    set(MORE_C_FLAGS "-x c++")
endif()

endif()

set_source_files_properties(${c4_SOURCES}
    PROPERTIES
        COMPILE_FLAGS ${MORE_C_FLAGS}
)
